package com.ying.config;

import com.ying.core.filter.LoginFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class LoginFilterConfig {

    @Bean
    public FilterRegistrationBean<LoginFilter> registeringFilter(){
        //通过FilterRegistrationBean实例设置优先级可以生效
        FilterRegistrationBean<LoginFilter> bean = new FilterRegistrationBean<LoginFilter>();
        bean.setFilter(new LoginFilter());//注册自定义过滤器
        bean.setName("loginFilter");//过滤器名称
        bean.addUrlPatterns("/api/*");//过滤所有路径
        bean.setOrder(1);//优先级，越低越优先
        bean.addInitParameter("excludedUris", "/api/user/login,  /captcha/get,/captcha/check ,/api/user/captcha-check," +
                "/api/user/oauth/gitee/callback, /api/user/oauth/oschina/callback, /api/user/oauth/github/callback," +
                "/api/user/oauth/render/gitee,/api/user/oauth/render/oschina, /api/user/oauth/render/github");//需要排除的uri
        return bean;
    }
}
